/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util.docsCache;

/**
 * 
 * @author Boulat
 */

class DocPosition {
	private String file;
	private int docStartLine;
	private int docEndLine;

	/**
	 * 
	 * @param file
	 *            file in which term was located.
	 * @param docStartLine
	 *            line where documents begin.
	 * @param docEndLine
	 *            line where the document ends.
	 */
	DocPosition(String file, int docStartLine, int docEndLine) {
		this.file = file;
		this.docStartLine = docStartLine;
		this.docEndLine = docEndLine;
	}

	/**
	 * 
	 * @param str
	 *            string will be separated in order to obtain file, start line
	 *            and end line of document.
	 * @return the file containing the term, the starting line of the text as
	 *         well as the ending line are sent back to the contructor of
	 *         DocPosition.
	 */
	static DocPosition fromString(String str) {
		String[] components = str.split("\\|");
		String file = components[0];
		int startLine = Integer.parseInt(components[1]);
		int endLine = Integer.parseInt(components[2]);
		return new DocPosition(file, startLine, endLine);
	}

	/**
	 * Converts information to string.
	 */
	@Override
	public String toString() {
		return file + "|" + String.valueOf(docStartLine) + "|"
				+ String.valueOf(docEndLine);
	}

	/**
	 * 
	 * @return returns the file which contains the term.
	 */
	String getFile() {
		return file;
	}

	/**
	 * 
	 * @param file
	 *            contains the file which will be set as the file in use.
	 */
	void setFile(String file) {
		this.file = file;
	}

	/**
	 * 
	 * @return returns the starting line of the document in which the term(s)
	 *         are stored.
	 */
	int getDocStartLine() {
		return docStartLine;
	}

	/**
	 * 
	 * @param docStartLine
	 *            holds the starting line of the document containing the term.
	 */
	void setDocStartLine(int docStartLine) {
		this.docStartLine = docStartLine;
	}

	/**
	 * 
	 * @return returns the ending line of the document in which the term(s) are
	 *         stored.
	 */
	int getDocEndLine() {
		return docEndLine;
	}

	/**
	 * 
	 * @param docEndLine
	 *            holds the ending line of the document containing the term.
	 */
	void setDocEndLine(int docEndLine) {
		this.docEndLine = docEndLine;
	}
}
